From 340e1dc132865deb6385fdca50a5c3294db5a6f0 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Fri, 11 May 2007 15:54:47 +0000 Subject: [PATCH] - Added the rest of the XHTML entities to the google reader in a slightly more reasonable form. Letting expat do the heavy lifting for entity substitutions. - Replaced ugly O(n^2) string replacement with one that's closer to O(n). The fact that TheDailyWTF just featured code like the code that was here originally is just a coincidence, really. --- google.c | 50 ++--- xhtmlent.c | 515 +++++++++++++++++++++++++++++++++++++++++++++++++++ xmlgeneric.c | 10 + xmlgeneric.h | 2 + 4 files changed, 555 insertions(+), 22 deletions(-) create mode 100644 xhtmlent.c diff --git a/google.c b/google.c index b2ff877f6..1ad9aef86 100644 --- a/google.c +++ b/google.c @@ -406,31 +406,37 @@ google_read(void) } if ( end ) { strcpy(end,"/table>"); - end = panel; - while ( (end = strstr( end, "\\\"" ))) { - memmove( end, end+1, strlen(end)+1 ); - } - end = panel; - while ( (end = strstr( end, "\\042"))) { - memmove( end, end+3, strlen(end+3)+1 ); - *end = '\"'; - } - end = panel; - while ( (end = strstr( end, "\\'" ))) { - memmove( end, end+1, strlen(end)+1 ); - } - end = panel; - while ( (end = strstr( end, " nowrap "))) { - memcpy( end+1, " ", 6 ); - } - - end = panel; - while ( (end = strstr( end, " "))) { - memcpy( end, " ", 6); - } + char *to = panel; + char *from = panel; + while ( *from ) { + if ( !strncmp( from, "\\\"", 2 )) { + *to++ = '"'; + from += 2; + } + else if ( !strncmp( from, "\\042", 4)) { + *to++ = '"'; + from += 4; + } + else if ( !strncmp( from, "\\'", 2)) { + *to++ = '\''; + from += 2; + } + else if ( !strncmp( from, " nowrap ", 8)) { + *to++ = ' '; + from += 8; + } + else { + *to++ = *from++; + } + } + *to = '\0'; + xml_deinit(); xml_init( NULL, google_map, NULL ); + xml_readprefixstring( "" ); xml_readstring( panel ); } } diff --git a/xhtmlent.c b/xhtmlent.c new file mode 100644 index 000000000..499122dd7 --- /dev/null +++ b/xhtmlent.c @@ -0,0 +1,515 @@ +char *xhtml_entities = +"\n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +" \n" +" \n" +"\n" +" \n" +" \n" +" \n" +"\n" +"\n" +" \n" +" \n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +"\n" +"\n" +"\n" +" \n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +" \n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +" \n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +" \n" +"\n" +" \n" +" \n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +"\n" +"\n" +"\n" +" \n" +"\n" +"\n" +" \n" +"\n" +" \n" +" \n" +" \n" +; diff --git a/xmlgeneric.c b/xmlgeneric.c index 3763e7398..2b8661d38 100644 --- a/xmlgeneric.c +++ b/xmlgeneric.c @@ -288,6 +288,16 @@ void xml_readstring( char *str ) XML_ParserFree(psr); } +void xml_readprefixstring( char *str ) +{ + int len = strlen(str); + if (!XML_Parse(psr, str, len, 0)) { + fatal( MYNAME ":Parse error at %d: %s\n", + (int) XML_GetCurrentLineNumber(psr), + XML_ErrorString(XML_GetErrorCode(psr))); + } +} + void xml_ignore_tags(const char **taglist) { xg_ignore_taglist = taglist; diff --git a/xmlgeneric.h b/xmlgeneric.h index 0e16b589c..0ce0834b9 100644 --- a/xmlgeneric.h +++ b/xmlgeneric.h @@ -35,6 +35,7 @@ typedef struct xg_tag_mapping { const char *tag_name; } xg_tag_mapping; +extern char *xhtml_entities; void write_xml_entity(gbfile *ofd, const char *indent, const char *tag, const char *value); @@ -58,4 +59,5 @@ void xml_ignore_tags(const char **taglist); void xml_init(const char *fname, xg_tag_mapping *tbl,const char *encoding); void xml_read(void); void xml_readstring(char *str); +void xml_readprefixstring(char *str); void xml_deinit(void); -- 2.30.2